package com.test.springmybatis;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class ParallelStreamExample {
    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        // 使用 AtomicInteger 来保证线程安全
        AtomicInteger sum = new AtomicInteger();

        // 使用 parallelStream 来累加元素
        numbers.parallelStream()
                .forEach(num -> sum.addAndGet(num));
        numbers.forEach(num -> System.out.println(num));
        numbers.parallelStream().forEach(num -> System.out.println(num));
        System.out.println("Sum: " + sum.get());
    }
}
